float3 eyePosition;
float4x4 World;
float4x4 WVP;

TextureCube tex;

sampler cubeSampler = sampler_state {
    texture = <tex>;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    AddressU = CLAMP;
    AddressV = CLAMP;
};


struct VertexShaderInput
{
    float4 Position : POSITION0;
    float3 Normal   : NORMAL0;
};

struct VertexShaderOutput
{
    float4 Position  : POSITION0;
    float3 PositionW : TEXCOORD1;
    float3 Normal    : TEXCOORD2;
};

VertexShaderOutput VSGeneral(VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;

    output.Position = mul(input.Position, WVP);

    output.PositionW = mul(input.Position,World);

    output.Normal = mul(input.Normal,(float3x3)World);
    
    return output;
}

float4 PSAmbient(VertexShaderOutput input) : COLOR0
{
    float3 N = normalize(input.Normal);
    float3 I = input.PositionW - eyePosition;
    I = normalize(I);

    float3 R = reflect(I,N);
    float3 reflectedColor = texCUBE(cubeSampler,R);


    return float4(reflectedColor,1);
}


technique Reflect
{
    pass Pass1
    {
        VertexShader = compile vs_3_0 VSGeneral();
        PixelShader = compile ps_3_0 PSAmbient();
    }
}